package wu.example.orderserver.filter;


import com.alibaba.fastjson.JSONObject;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.rpc.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author benjamin_5
 * @Description 自定义拦截器
 * @date 2024/8/28
 */
@Activate(group = "log", value = "id")
public class LogInterceptor implements Filter {

    private final static Logger logger = LoggerFactory.getLogger(LogInterceptor.class);

    @Override
    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
        String params = JSONObject.toJSONString(invocation.getArguments());
        logger.info(String.format("接口：%s，调用参数：%s",invocation.getMethodName(), params));
        Result result = invoker.invoke(invocation);
        String resultStr = JSONObject.toJSONString(result.getValue());
        logger.info(String.format("接口：%s，返回结果：%s",invocation.getMethodName(), resultStr));
        return result;
    }
}
